package top.honlnk.czuan.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
import top.honlnk.czuan.pojo.entity.*;

import java.util.List;

@Mapper
public interface AddMapper {

    // 更新words表的isAlone字段
    @Update("update words set is_alone = #{value}, update_by = #{updateBy} where id = #{wordId}")
    void updateWordsIsAlone(Integer wordId, Integer value, String updateBy);

    // 添加翻译
//    @Insert("insert into translations(id, translation, part_id, update_by, created_by) values (#{id}, #{translation}, #{partId}, #{updateBy}, #{createdBy})")
    void addTranslations(List<Translations> translations);

    // 添加单词
    void addWord(Words words);
    // 添加单词与翻译的关系
    @Insert("insert into word_translation(word_id, translation_id) values (#{wordId}, #{translationId})")
    void addWordTranslationRelation(Integer wordId, Integer translationId);
    // 添加单词与根词的关系
    @Insert("insert into word_root(word_id, root_id) values (#{wordId}, #{rootId})")
    void addWordRootRelation(Integer wordId, Integer rootId);
    // 更新词根的count字段
    @Update("update roots set count = count + #{value} where id = #{rootId}")
    void updateRootCount(Integer rootId, Integer value);
    // 添加单词与前缀的关系
    @Insert("insert into word_prefix(word_id, prefix_id) values (#{wordId}, #{prefixId})")
    void addWordPrefixRelation(Integer wordId, Integer prefixId);
    // 更新词缀的count字段
    @Update("update prefixes set count = count + #{value} where id = #{prefixId}")
    void updatePrefixCount(Integer prefixId, Integer value);
    // 添加单词与后缀的关系
    @Insert("insert into word_suffix(word_id, suffix_id) values (#{wordId}, #{suffixId})")
    void addWordSuffixRelation(Integer wordId, Integer suffixId);
    // 更新后缀的count字段
    @Update("update suffixes set count = count + #{value} where id = #{suffixId}")
    void updateSuffixCount(Integer suffixId, Integer value);

    // 添加根词
    void addRoot(Roots root);
    // 添加根词与翻译的关系
    @Insert("insert into root_translation(root_id, translation_id) values (#{rootId}, #{translationId})")
    void addRootTranslationRelation(Integer rootId, Integer translationId);

    // 添加前缀
    void addPrefix(Prefixes prefix);
    // 添加前缀与翻译的关系
    @Insert("insert into prefix_translation(prefix_id, translation_id) values (#{prefixId}, #{translationId})")
    void addPrefixTranslationRelation(Integer prefixId, Integer translationId);

    // 添加后缀
    void addSuffix(Suffixes suffix);
    // 添加后缀与翻译的关系
    @Insert("insert into suffix_translation(suffix_id, translation_id) values (#{suffixId}, #{translationId})")
    void addSuffixTranslationRelation(Integer suffixId, Integer translationId);


    // 添加新的翻译时向words表中的translations_id_list字段尾部添加内容
//    @Update("update words set translations_id_list = JSON_ARRAY_APPEND(translations_id_list,'$', #{translationsId}) where id = #{wordId}")
    void updateTranslationsIdList(Integer wordId, Integer translationsId, Integer partId);

    void updateRootTranslationsIdList(Integer wordId, Integer rootId, String rTIds);

    void updatePrefixTranslationsIdList(Integer wordId, Integer prefixId, String pTIds);

    void updateSuffixTranslationsIdList(Integer wordId, Integer suffixId, String sTIds);

}
